<template>
  <Modal v-model="modal" title="人员" @on-cancel="canceledit">
    <Select
      v-model="params.member_id"
      filterable
      multiple
      placeholder="人员选择"
    >
      <Option
        v-for="item in memberList"
        :value="item.value"
        :key="item.value"
        :disabled="item.disabled"
        >{{ item.label }}</Option
      >
    </Select>
    <div slot="footer">
      <Button @click="canceledit">取消</Button>
      <Button @click="submitedit" type="primary">确认</Button>
    </div>
  </Modal>
</template>

<script>
import { netsettingmemberlist, netsettingbindmember } from "@/api/hqapi";
export default {
  name: "Personnel",
  data() {
    return {
      memberList: [],
      modal: false,
      params: { id: "", member_id: [] },
    };
  },
  methods: {
    initial(row) {
      this.params.id = row.id;
      netsettingmemberlist({ id: row.id }).then((res) => {
        this.memberList = res.list;
        this.params.member_id = res.member_ids;
        // this.memberList.forEach(item => {
        //     if (item.selected) {
        //         this.params.member_id.push(item.value)
        //     }
        // });
        this.modal = true;
      });
    },
    canceledit() {
      this.modal = false;
    },
    submitedit() {
      let params = {
        id: this.params.id,
        member_id: this.params.member_id.join(","),
      };
      netsettingbindmember(params).then((res) => {
        this.$Message.success("人员绑定成功");
        this.$emit("askData");
        this.modal = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
